Census Tract Mapping
create_tract_map.RdGenerate Census Tract Maps for Census Data
Usage
create_tract_map(
tract.tbl,
tract.lyr,
map.title = NULL,
map.subtitle = NULL,
map.title.position = NULL,
legend.title = NULL,
legend.subtitle = NULL,
map.lat = 47.615,
map.lon = -122.257,
map.zoom = 8.5,
wgs84 = 4326
)Arguments
- tract.tbl
A data frame of census data by Census Tract to map.
- tract.lyr
A spatial layer of Census Tracts.
- map.title
Character. Map title.
- map.subtitle
Character. A map subtitle that will appear below the map title.
- map.title.position
Character. Place the map title and subtitle in 'bottomleft','bottomright', topleft', or 'topright'.
- legend.title
Character. Legend title.
- legend.subtitle
Character. A legend subtitle that will appear below the legend subtitle.
- map.lat
A numeric value for the latitude of the center point for your map. Defaults to 47.615 (PSRC Region)
- map.lon
A numeric value for the longitude of the center point for your map. Defaults to -122.257 (PSRC Region)
- map.zoom
A numeric value for the default zoom level for your map. Defaults to 8.5 (PSRC Region)
- wgs84
A code for mapping, this should be pulled out of the function or something
Examples
library(sf)
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:psrccensus’:
#>
#> between, first, last
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
tract.big.tbl <- psrccensus::get_acs_recs(geography='tract',table.names=c('B03002'),years=c(2019))
#> Getting data from the 2015-2019 5-year ACS
#> Using FIPS code '53' for state 'Washington'
#> Using FIPS code '033' for 'King County'
#> Using FIPS code '035' for 'Kitsap County'
#> Using FIPS code '053' for 'Pierce County'
#> Using FIPS code '061' for 'Snohomish County'
tract.tbl <- tract.big.tbl %>%
filter(label=='Estimate!!Total:!!Not Hispanic or Latino:!!Black or African American alone')
tract.url <- paste0("https://services6.arcgis.com/GWxg6t7KXELn1thE/arcgis/rest/services/",
"tract2010_nowater/FeatureServer/0/query?where=0=0&outFields=*&f=pgeojson")
tract.lyr<-st_read(tract.url)
#> Reading layer `OGRGeoJSON' from data source
#> `https://services6.arcgis.com/GWxg6t7KXELn1thE/arcgis/rest/services/tract2010_nowater/FeatureServer/0/query?where=0=0&outFields=*&f=pgeojson'
#> using driver `GeoJSON'
#> Simple feature collection with 773 features and 21 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -123.0234 ymin: 46.72799 xmax: -120.9062 ymax: 48.29924
#> Geodetic CRS: WGS 84
create_tract_map(tract.tbl=tract.tbl, tract.lyr=tract.lyr,
map.title='Black, non-Hispanic Population',
map.title.position='topleft', legend.title='Black, Non-Hispanic Population',
legend.subtitle='by Census Tract')